package com.jdkj.tools.util;

import com.jdkj.tools.domain.ProjectType;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

public class ParseProject {
    public static   List<ProjectType> parseHtml() {
//        Jsoup.connect("http://192.168.11.7:8083/secure/BrowseProjects.jspa?selectedCategory=all&selectedProjectType=all");
         //解析HTML文档的
       String str="<div class=\"p-list\"><table class=\"aui\"><thead><tr><th class=\"project-list-name sortable active\" data-sort-key=\"name\">项目<span class=\"aui-icon aui-icon-small aui-iconfont-new-arrow-up\"></span></th><th class=\"project-list-key sortable \" data-sort-key=\"key\">关键字</th><th class=\"project-list-type sortable \" data-sort-key=\"projectTypeName\">项目类型</th><th class=\"project-list-lead sortable \" data-sort-key=\"lead\">项目负责人</th><th class=\"project-list-category sortable \" data-sort-key=\"projectCategoryId\">项目类别</th><th class=\"project-list-url\">URL</th></tr></thead><tbody class=\"projects-list\"><tr data-project-id=\"10002\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202401\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2024-01  美标交流桩项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2024-01  美标交流桩项目</a></td><td class=\"cell-type-key\">EP202401</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10003\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202402\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2024-02  欧标直流桩项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2024-02  欧标直流桩项目</a></td><td class=\"cell-type-key\">EP202402</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10005\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202404\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2024-04  960KW分体桩自研项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2024-04  960KW分体桩自研项目</a></td><td class=\"cell-type-key\">EP202404</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10006\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202407\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2024-07  直流桩自研项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2024-07  直流桩自研项目</a></td><td class=\"cell-type-key\">EP202407</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10007\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202424\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2024-24  V2G30KW项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2024-24  V2G30KW项目</a></td><td class=\"cell-type-key\">EP202424</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10008\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202425\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2024-25  OCPP项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2024-25  OCPP项目</a></td><td class=\"cell-type-key\">EP202425</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10009\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202501\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-01  船电宝项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-01  船电宝项目</a></td><td class=\"cell-type-key\">EP202501</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10010\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202502\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-02  600KW分体桩项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-02  600KW分体桩项目</a></td><td class=\"cell-type-key\">EP202502</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10011\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EO202503\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-03  BYD小直流项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-03  BYD小直流项目</a></td><td class=\"cell-type-key\">EO202503</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10100\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202504\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-04  定制、迭代、升级、维护\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-04  定制、迭代、升级、维护</a></td><td class=\"cell-type-key\">EP202504</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10104\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202505\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-05 平台定制与运营\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-05 平台定制与运营</a></td><td class=\"cell-type-key\">EP202505</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10105\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202506\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-06 UI设计\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-06 UI设计</a></td><td class=\"cell-type-key\">EP202506</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10106\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202507\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-07 欧标交流桩项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-07 欧标交流桩项目</a></td><td class=\"cell-type-key\">EP202507</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10107\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202508\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-08 国标14KW交流桩项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-08 国标14KW交流桩项目</a></td><td class=\"cell-type-key\">EP202508</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10108\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202509\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-09  国网SDK平台接入项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-09  国网SDK平台接入项目</a></td><td class=\"cell-type-key\">EP202509</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10201\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202510\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-10 1MW输出终端\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-10 1MW输出终端</a></td><td class=\"cell-type-key\">EP202510</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10202\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202511\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-11 电摩8KW项目\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-11 电摩8KW项目</a></td><td class=\"cell-type-key\">EP202511</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"zhouweiming\" id=\"_zhouweiming\" href=\"/secure/ViewProfile.jspa?name=zhouweiming\">周卫明</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr><tr data-project-id=\"10203\"><td data-cell-type=\"name\" class=\"cell-type-name\"><a href=\"/browse/EP202512\" atltoken=\"false\" data-track-click=\"projects.browse.project\" original-title=\"EP-2025-12 OCPP平台搭建\"><span class=\"aui-avatar aui-avatar-small aui-avatar-project jira-system-avatar\"><span class=\"aui-avatar-inner\"><img src=\"/secure/projectavatar?size=small\"></span></span>EP-2025-12 OCPP平台搭建</a></td><td class=\"cell-type-key\">EP202512</td><td class=\"cell-type-project-type\"><img src=\"\" class=\"project-type-icon\" title=\"Software\"></td><td class=\"cell-type-user\"><a class=\"user-hover\" rel=\"wujun\" id=\"_wujun\" href=\"/secure/ViewProfile.jspa?name=wujun\">吴骏</a></td><td class=\"cell-type-category\">无分类</td><td class=\"cell-type-url\">无URL</td></tr></tbody></table></div>";

        Document document = Jsoup.parse(str);
        List<ProjectType> list=new ArrayList<>();
        // 1. 选出所有的 <tr>（每一行）
        Elements rows = document.select("tbody.projects-list tr");
        for (Element row : rows) {


            // 2. 在这一行中，取出项目名称列里的 <a> 标签
            Element link = row.selectFirst("td.cell-type-name a");
            String originalTitle = link.attr("original-title");

            // 3. 在这一行中，取出关键字列的文本
            String projectKey = row.selectFirst("td.cell-type-key").text();
            ProjectType projectType = new ProjectType();

            // 1. 取 data-project-id
            String projectId = row.attr("data-project-id");
            projectType.setProjectId(projectId);

            projectType.setProjectName(originalTitle);
            projectType.setProjectKey(projectKey);
            list.add(projectType);
//            System.out.println("original-title=" + originalTitle + "  cell-type-key=" + projectKey);
        }
        return list;
    }
}